%{
    #define _SKIP_YYFLEXLEXER_
    #include "scanner.ih"

    #include "../parser/parser.h"
    #include <string>
    
    using namespace std;
%}

%option yyclass="Scanner" outfile="scanner.cc"
%option c++ 8bit warn noyywrap yylineno

ws      [ \t\n]+

alpha   [A-Za-z]
dig     [0-9]


unquoted    ({alpha}|{dig}|\$)({alpha}|{dig}|[_.\-/$]|[\<\>])*

num1    [-+]?{dig}+\.?([eE][-+]?{dig}+)?
num2    [-+]?{dig}*\.{dig}+([eE][-+]?{dig}+)?
num  {num1}|{num2}


%x comment
%x cfg_str
%x path
%%

#		BEGIN(comment);
<comment>[^\n]	/* mangia tutto il corpo del commento */
<comment>\n	BEGIN(INITIAL);

<cfg_str>[^\"]
<cfg_str>"\\"+"\""	BEGIN(path);
<cfg_str>"\""	{BEGIN(INITIAL); return Parser::QUOT_S;};
<path>[^("\\"+"\"")]
<path>"\\"+"\""	BEGIN(cfg_str);

"=="		return Parser::BID_UNB;
"=>"		return Parser::BID_BUF;
"->"		return Parser::DIR_BUF;
"=-"		return Parser::BID_BUF_BOTH;
"pip"		return Parser::PIP;
"outpin"	return Parser::OUTPIN;
"driver"	return Parser::DRIVER;
"inpin"		return Parser::INPIN;
"load"		return Parser::LOAD;
","		return Parser::COMMA;
"vcc"		return Parser::VCC;
"vdd"		return Parser::VDD;
"power"		return Parser::POWER;
"gnd"		return Parser::GND;
"ground"	return Parser::GROUND;
"wire"		return Parser::WIRE;
"net"		return Parser::NET;
";"		return Parser::SEMICOLON;
"cfg \""	BEGIN(cfg_str); return Parser::CFG;
"module"	return Parser::MODULE;
"unplaced"	return Parser::UNPLACED;
"bonded"	return Parser::BONDED;
"unbonded"	return Parser::UNBONDED;
"placed"	return Parser::PLACED;
"inst"		return Parser::INST;
"instance"	return Parser::INSTANCE;
"endmodule"	return Parser::ENDMODULE;
"port"		return Parser::PORT;
"design"	return Parser::DESIGN;
"v"+{num}	yyval->s_val = new string(yytext); return Parser::VERSION;

{ws}		{};

{unquoted}	yyval->s_val = new string(yytext); return Parser::UNQUOT_S;
\"+{unquoted}+\" {
			yyval->s_val = new string(yytext);
			//yyval->s_val->erase(yyval->s_val->begin());
			//yyval->s_val->erase( --( yyval->s_val->end() ) );
			return Parser::QUOT_S;
		}
%%

